package com.tenement.service.impl;

import cn.hutool.core.util.StrUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.tenement.entity.Alipay;
import com.tenement.mapper.AlipayMapper;
import com.tenement.service.AlipayService;
import com.tenement.vo.QueryVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import static com.tenement.entity.table.AlipayTableDef.ALIPAY;
import static com.tenement.entity.table.PropertiesTableDef.PROPERTIES;

/**
 *  服务层实现。
 *
 * @author BertXie
 * @since 1.0.1
 */
@Service
@RequiredArgsConstructor
public class AlipayServiceImpl extends ServiceImpl<AlipayMapper, Alipay> implements AlipayService {


    private final AlipayMapper alipayMapper;


    @Override
    public Page<Alipay> list(QueryVo queryVo) {
        QueryWrapper queryWrapper = QueryWrapper.create()
                .from(ALIPAY)
                .select(ALIPAY.ALL_COLUMNS,PROPERTIES.ALL_COLUMNS)
                .leftJoin(PROPERTIES).on(ALIPAY.UNIT_ID.eq(PROPERTIES.ID))
                .where(
                        PROPERTIES.ADDRESS.like(queryVo.getKeyWord(), StrUtil.isNotEmpty(queryVo.getKeyWord()))
                                .or(PROPERTIES.PROPERTY_NAME.like(queryVo.getKeyWord(),StrUtil.isNotEmpty(queryVo.getKeyWord())))
                                .or(PROPERTIES.COMMUNITY_NAME.like(queryVo.getKeyWord(),StrUtil.isNotEmpty(queryVo.getKeyWord())))
                );
        return alipayMapper.paginate(queryVo.getPage(), queryVo.getSize(),queryWrapper);
    }
}
